package org.acme.sync;

import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Data
public class SyncResponseWrap {

    Logger logger = LoggerFactory.getLogger(getClass());

    private String id;

    private Object object = new Object();

    private SyncRequest syncRequest;

    private SyncResponse syncResponse;

    public SyncResponseWrap(String id, SyncRequest syncRequest) {
        this.id = id;
        this.syncRequest = syncRequest;
    }

    public SyncResponse getSyncResponse() {
        synchronized (object){
            if (syncResponse == null) {
                try {
                    this.object.wait(10 * 1000);
                } catch (InterruptedException e) {

                }
            }
        }
        return syncResponse;
    }

    public void setSyncResponse(SyncResponse syncResponse) {
        synchronized (object){
            this.syncResponse = syncResponse;
            this.object.notify();
        }
    }
}
